package STUDENT.TRINHQUANGXUANDUC.OPPS.baitapmang.bai5;

public class Models {
	public String buBbly(int[] array) {
		String kq = "";
		for (int i = 0; i < array.length; i++) {
			for (int j = array.length - 1; j > 0; j--) {
				if (array[j] < array[j - 1]) {
					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
				}
			}
		}
		for (int i = 0; i < array.length; i++) {
			kq += array[i] + " ";
		}
		return kq;
	}

	public String insertSort(int[] array) {
		String kq = "";
		for (int i = 0; i < array.length; i++) {
			int index = i;
			while (index > 0 && array[index - 1] > array[index]) {
				int temp = array[index];
				array[index] = array[index - 1];
				array[index - 1] = temp;
			}
		}
		for (int i = 0; i < array.length; i++) {
			kq += array[i] + " ";
		}
		return kq;
	}

	public String selectionSort(int[] array) {
		String kq = "";
		for (int i = 0; i < array.length; i++) {
			int max = array[i];
			int index = i;
			for (int j = i + 1; j < array.length; j++) {
				if (max < array[j]) {
					max = array[j];
					index = j;
				}
			}
			if (index != i) {
				int temp = array[i];
				array[i] = array[index];
				array[index] = temp;
			}
		}
		for (int i = 0; i < array.length; i++) {
			kq += array[i] + " ";
		}
		return kq;
	}

	public String Revising(int[] array) {
		String kq = "";
		int count[] = new int[array.length];
		int j = 0;
		for (int i = array.length - 1; i >= 0; i--) {
			count[j] = array[i];
			j++;
		}
		for (int i = 0; i < count.length; i++) {
			kq += count[i] + " ";
		}
		return kq;
	}
}
